<template>
	<view class="g-h5 body-content">
		<u-navbar back-text="返回" title="标签"></u-navbar>
		<view class="search-view">
			<u-search placeholder="快速查找" :show-action="false" bg-color="#DFE0E4"></u-search>
		</view>
		<view class="search-view" style="padding-top: 10rpx;">
			<u-subsection :list="list" :current="0" bg-color="#DFE0E4"></u-subsection>
		</view>
		<view class="label-content-view">
			<view class="label-list">
				<view class="label-left-view">
					<view><u-icon name="minus-circle"></u-icon></view>
					<view class="ml-20">无标签</view>
				</view>
				<view class="label-right-view">
					<view class="mr-20">86</view>
					<view><u-icon name="arrow-right"></u-icon></view>
				</view>
			</view>
			<view class="user-menu-list">
				<view class="user-menu-list-top">
					<view class="user-menu-list-text">{{labelList.length}}个标签</view>
				</view>
				<view @tap.stop="addLabel"><u-icon name="plus-circle" size="34" color="#999"></u-icon></view>
			</view>
			<view class="label-list-content-view">
				<view class="label-list-view" v-for="(item,index) in labelList" :key="item.id">
					<view class="label-left-view">
						<view><u-icon name="minus-circle" size="36"></u-icon></view>
						<view class="ml-20">{{item.name}}</view>
					</view>
					<view class="label-right-view">
						<view><u-icon name="arrow-right"></u-icon></view>
					</view>
				</view>
			</view>
		</view>
		<u-tabbar v-model="tabCurrent" :list="tabList"></u-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [
					{ name: '自定义排序' },
					{ name: '名称排序' }
				],
				current: 0,
				labelList: [],
				tabList: [{
						iconPath: 'home',
						selectedIconPath: 'home-fill',
						text: '在读',
						customIcon: false,
						pagePath: '/pages/miniprogram/index'
						 					},
					{
						iconPath: 'photo',
						selectedIconPath: 'photo-fill',
						text: '书架',
						customIcon: false,
						pagePath: '/pages/miniprogram/books'
						 					},
					{
						iconPath: 'https://cdn.uviewui.com/uview/common/min_button.png',
						selectedIconPath: 'https://cdn.uviewui.com/uview/common/min_button_select.png',
						text: '书店',
						customIcon: false,
						pagePath: '/pages/miniprogram/bookshop'
						 					},
					{
						iconPath: 'play-right',
						selectedIconPath: 'play-right-fill',
						text: '我的',
						customIcon: false,
						pagePath: '/pages/miniprogram/user'
						 					},
						 				],
				tabCurrent: 0,
			}
		},
		onLoad() {
			this.labelList = this.$api.label_list()
		},
		methods: {
			addLabel(){
				uni.showModal({
					title:'提示',
					editable: true,
					placeholderText: '输入标签',
					success: res=>{
						if(res.content){
							this.$api.label_create({ name:res.content })
							this.labelList = this.$api.label_list()
							// this.labelList.unshift({
							// 	id: this.labelList.length + 1,
							// 	name: res.content
							// })
						}
					}
				})
			}
		}
	}
</script>

<style scoped>
	.search-view {
		padding: 30rpx 40rpx;
	}
	.label-content-view {
		padding: 0 40rpx;
	}
	.label-list {
		padding: 20rpx;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-radius: 20rpx;
	}
	.label-list-view {
		padding: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1rpx solid #999999;
	}
	.label-list-view:last-child {
		border-bottom: none;
	}
	.label-left-view {
		display: flex;
		align-items: center;
		font-size: 28rpx;
	}
	.label-right-view {
		display: flex;
		align-items: center;
		font-size: 24rpx;
		color: #999;
	}
	.user-menu-list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 20rpx;
	}
	.user-menu-list-top {
		display: flex;
		color: #999;
		font-size: 24rpx;
	}
	.user-menu-content {
		padding: 20rpx;
		background-color: #ffffff;
		border-radius: 20rpx;
		margin-top: 20rpx;
	}
	.menu-content-list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx;
		border-bottom: 1rpx solid #ECEDF1;
	}
	.menu-left-view {
		display: flex;
		align-items: center;
	}
	.label-list-content-view {
		padding: 0 20rpx;
		background-color: #fff;
		border-radius: 20rpx;
		margin-top: 20rpx;
	}
</style>